<?php if (!defined('BASEPATH'))exit('No direct script access allowed');
/**
 * 体验平台模块控制器
 */
class Mplat extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('plat_model');
        $this->load->model('users_model');
        $this->load->model('plat_award_list_model');
        $this->load->model('users_log_model');
        $this->assign("module", "mplat");
    }
    //首页
//    function index() {
//        $where = array();
//        $where['is_show'] = 1;
//        $where['is_online'] = 1;
//        $ilist = $this->plat_model->get_list($where,0,30);
//        foreach ($ilist as $key=>$val){
//            $class_str = $val['company_bg_type'] ? $this->bgType[$val['company_bg_type']]["class"] : $this->bgType[0]['class'];
//            $ilist[$key]['class'] = $class_str;
//            $ilist[$key]["url"] = site_url("mplat_".$val['name_en']);
//            $ilist[$key]['max_award'] = number_format($val["max_award"]);
//            $ilist[$key]['logo_detail'] = strstr($val['logo_detail'], "http://") ? $val['logo_detail'] : $this->img_url.$val['logo_detail'];
//        }
//        
//        $where = array();
//        //暂停体验的平台
//        $where['is_show'] = 1;
//        $where['is_online'] = 0;
//        $nlist = $this->plat_model->get_list($where,0,20);
//        foreach ($nlist as $key=>$val){
//            $class_str = $val['company_bg_type'] ? $this->bgType[$val['company_bg_type']]["class"] : $this->bgType[0]['class'];
//            $nlist[$key]['class'] = $class_str;
//            $nlist[$key]["url"] = site_url("mplat_".$val['name_en']);
//            $nlist[$key]['max_award'] = number_format($val["max_award"]);
//            $nlist[$key]['logo_detail'] = strstr($val['logo_detail'], "http://") ? $val['logo_detail'] : $this->img_url.$val['logo_detail'];
//        }
//        $this->assign('ilist', $ilist);
//        $this->assign('nlist', $nlist);
//        $this->display('mplat/index.html');
//    }
    //首页
    function index() {
        //热门推荐
        $hot_plats = $this->plat_hot();
        
        //筛选平台
        $filter_plats = $this->plat_filter();
        
        //正在体验
        $doing_plats = $this->plat_doing();
        
        //暂停体验
        //$done_plats = $this->plat_done();
        
        //投资问答
        $wenda_plats = $this->plat_index_wenda();
        //网贷文章
        $article_plats = $this->plat_index_article();
        //优质排行榜
        $board_plats = $this->plat_board();
        
        $this->assign('hot_plats', $hot_plats);
        $this->assign('filter_plats', $filter_plats);
        $this->assign('doing_plats', $doing_plats);
        $this->assign('done_plats', $done_plats);
        $this->assign('wenda_plats', $wenda_plats);
        $this->assign('article_plats', $article_plats);
        $this->assign('board_plats', $board_plats);
        $this->display('mplat/index.html');
    }
    
    //热门推荐
    private function plat_hot(){
        $where = "p.is_recommend = 1 and p.is_online = 1 and p.is_show = 1 and is_work = 1";
        $list = $this->db->query("select p.id,p.name_ch,p.name_en,p.add_interest,p.logo_detail from tan_plat p where $where order by p.sort desc,p.id desc limit 5")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]["detail_url"] = site_url("mplat_".$val['name_en']);
            $list[$key]['add_interest'] = $val['add_interest'] * 100;
        }
        return $list;
    }
    
    //筛选平台
    private function plat_filter(){
        $this->settings->load('platlist');
        $list= setting('platlist');
        foreach ($list as $key=>$val){
            foreach ($val['children'] as $k=>$v){
                $val['children'][$k]['detail_url'] = site_url("mplat_".$v['name_en']);
            }
            $list[$key]['children'] = $val['children'];
            $list[$key]['ul_array'] = array_chunk($val['children'], 12);
        }
        return $list;
    }
    
    //正在体验
    private function plat_doing(){
        $where = "p.is_online = 1 and p.is_show = 1 and p.is_work = 1";
        $query_params = "p.id,p.name_ch,p.name_en,p.add_interest,p.plat_interest_desc,p.logo_detail,p.require_amount_desc,b.company_bg_type,i.bg_type";
        $list = $this->db->query("select $query_params from tan_plat p left join tan_plat_info i on i.plat_en = p.name_en "
                . "left join tan_plat_baseinfo b on b.plat_en = p.name_en where $where group by p.name_en order by p.is_show desc,p.sort desc ")->result_array();
        foreach ($list as $key=>$val){
            $bg_type = $this->db->query("select * from tan_plat_category where id = $val[bg_type] order by id desc limit 1")->row_array();
            
            $list[$key]["detail_url"] = site_url("mplat_".$val['name_en']);
            $list[$key]['class'] = $val['company_bg_type'] ? $this->bgType[$val['company_bg_type']]["class"] : $this->bgType[0]['class'];
            $list[$key]['add_interest'] = $val['add_interest'] * 100;
            $list[$key]['bg_type_name'] = $bg_type['title'];
        }
        return $list;
    }
    //暂停体验
    private function plat_done(){
        $where = "p.is_online = 0 and p.is_show = 1";
        $query_params = "p.id,p.name_ch,p.name_en,p.add_interest,p.plat_interest_desc,p.logo_detail,p.require_amount_desc,b.company_bg_type,i.bg_type";
        $list = $this->db->query("select $query_params from tan_plat p left join tan_plat_info i on i.plat_en = p.name_en "
                . "left join tan_plat_baseinfo b on b.plat_en = p.name_en where $where group by p.name_en order by p.is_show desc,p.sort desc ")->result_array();
        foreach ($list as $key=>$val){
            $bg_type = $this->db->query("select * from tan_plat_category where id = $val[bg_type] order by id desc limit 1")->row_array();
            
            $list[$key]["detail_url"] = site_url("mplat_".$val['name_en']);
            $list[$key]['class'] = $val['company_bg_type'] ? $this->bgType[$val['company_bg_type']]["class"] : $this->bgType[0]['class'];
            $list[$key]['add_interest'] = $val['add_interest'] * 100;
            $list[$key]['bg_type_name'] = $bg_type['title'];
        }
        return $list;
    }
    //投资问答
    private function plat_index_wenda(){
        $where = "tags_name like '%平台曝光%' and status = 1 and is_show = 1";
        $list = $this->db->query("select id,title,answernum from tan_bbs_wenda where $where order by hot desc,sort desc,id desc limit 6")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['wenda_url'] = www_base_url("wenda/".  encrypt_wenda_id($val['id']));
        }
        return $list;
    }
    //网贷文章
    private function plat_index_article(){
        $where = "(a.tags_name like '%互联网金融%' or a.tags_name like '%网贷%') and a.status = 1 and a.show = 1";
        $list = $this->db->query("select a.id,a.title,a.authorid,a.readnum,i.head_img,i.nickname from tan_bbs_article a left join tan_users_info i on i.user_id = a.authorid where $where order by a.hot desc,a.sort desc,a.id desc limit 6")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['detail_url'] = www_base_url("p/". encrypt_article_id($val['id']));
            $list[$key]['space_url'] = www_base_url("u/". encrypt_user_id($val['authorid']));
            $list[$key]['readnum'] = number_format($val['readnum']);
        }
        return $list;
    }
    //优质排行榜
    private function plat_board(){
        $list = $this->db->query("select i.plat_ch,i.plat_en,i.total_amount,p.logo_detail from tan_plat_info i left join tan_plat p on p.name_en = i.plat_en order by i.total_amount desc limit 5")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['detail_url'] = site_url("mplat_".$val['plat_en']);
            $list[$key]['amount'] = format_amount($val['total_amount']);
        }
        return $list;
    }
    
    //平台列表筛选页
    function lists(){
        $this->settings->load('platcate');
        $cates = setting('platcate');
        $this->assign('cates', $cates);
        $this->assign('action', 'mplat');
        $this->display('mplat/lists.html');
    }
    
    //体验产品详情页
//    function detail($plat_id){
//        if(!$plat_id) redirect ("mplat");
//        $item = $this->plat_model->get_info(array('name_en'=>$plat_id,'is_hide'=>1));
//        if(!$item) redirect ("mplat");
//        $item['plat_id'] = $item['id'];
//        $rules = $this->plat_model->get_rules(array('plat_id'=>$item['plat_id'],'is_show'=>1));
//        $baseinfo = $this->plat_model->get_baseinfo(array('plat_en'=>$item['name_en']));
//        $baseinfo['company_bg_type'] = $baseinfo['company_bg_type'] ? $this->bgType[$baseinfo['company_bg_type']]['title'] : $this->bgType[0]['title'];
//        $cpa = $this->plat_model->check_ab_cpa(array('user_id'=>$this->userinfo['user_id'],'plat_en'=>$item['name_en']));
//        foreach ($rules as $key=>$val){
//            $where = array();
//            $where['plat_id'] = $item['plat_id'];
//            $where['rule_step'] = $val['step'];
//            $where['user_id'] = $this->userinfo['user_id'];
//            $award = $this->plat_model->get_award_list($where);
//            $rules[$key]['is_step'] = $award ? 1 : "";
//            $rules[$key]['is_receive'] = $award['is_receive'] ? 1 : 0;
//            $rules[$key]['award'] = number_format($val['award']);
//            $rules[$key]['award_id'] = $award['id'];
//        }
//        $item['jump_url'] = site_url('jump_'.$item['name_en']);
//        if($cpa){
//            $cpa['usernamep'] = strlen($cpa['usernamep']) > 11 ? name_formart($cpa['usernamep']) : $cpa['usernamep'];
//            if($item['is_fast_login'] == 0){//非快速登录
//                $interface = $this->plat_model->get_interface(array('plat_en'=>$item['name_en']));
//                $item['login_url'] = $interface['login_link'];
//            }else{
//                $item['login_url'] = site_url('mplat/login/'.$item['name_en']);
//            }
//            
//        }
//        //判断是否可用自动加载
//        $is_auto_load = 0;
//        if($cpa && $item['is_fast_query'] == 1 && $item['is_show'] == 1 ){
//            if($item['plat_type'] == 1){
//                //if($cpa['is_finish'] == 0){
//                    $is_auto_load = 1;
//                //}
//            }else{
//                $is_auto_load = 1;
//            }
//        }
//        $item['max_award'] = number_format($item['max_award']); 
//        $item['logo_list'] = strstr($item['logo_list'], "http://") ? $item['logo_list'] : $this->img_url.$item['logo_list'];
//        $item['query_url'] = site_url('query_'.$item['name_en']);
//        
//        //最近体验用户
//        $exper_list = $this->plat_award_list_model->get_expers_list(array(),0,20);
//        foreach ($exper_list as $key=>$val){
//            $exper_list[$key]['award'] = number_format($val['award']);
//            $exper_list[$key]['username'] = name_formart($val['username']);
//        }
//        $this->assign('exper_list', $exper_list);
//        $this->assign('cpa', $cpa);
//        $this->assign('baseinfo', $baseinfo);
//        $this->assign('rules', $rules);
//        $this->assign('is_auto_load',$is_auto_load);
//        $this->assign('item', $item);
//        $this->assign('action', 'mplat');
//        $this->display('mplat/detail.html');
//    }
    function detail($plat_id){
        if(!$plat_id) redirect ("mplat");
        $query_params = "p.id,p.name_ch,p.name_en,p.plat_interest,p.add_interest,p.logo_detail,p.logo_list,p.exper_require_desc,p.website,p.is_show,p.is_online,p.is_work,p.is_duijie,p.is_fast_login,p.website,p.is_interest_mode,i.tiyanguize";
        $item = $this->db->query("select $query_params from tan_plat p left join tan_plat_info i on i.plat_en = p.name_en where p.name_en = '$plat_id' order by p.id desc limit 1")->row_array();
        if(!$item) redirect ("mplat");
        $item['total_interest'] = (($item['plat_interest'] + $item['add_interest']) * 100)."%";
        $item['plat_interest'] = ($item['plat_interest'] * 100)."%";
        $item['add_interest'] = ($item['add_interest'] * 100)."%";
        $item['exper_require_desc'] = $item['exper_require_desc'] ? explode("|", $item['exper_require_desc']) : "";
        $item['jump_url'] = site_url("jump_".$item['name_en']);
        $item['wenda_seach_url'] = www_base_url("wenda/search")."?kw=".$item['name_ch'];
        $tag = $this->db->query("select id,name from tan_bbs_article_tags where name like '%$item[name_ch]%' order by id desc limit 1")->row_array();
        if($tag){
            $item['article_seach_url'] = www_base_url("p/tag-".$tag['id']);
        }else{
            $item['article_seach_url'] = www_base_url("");
        }
        //判断是否cpa
        $cpa = array();
        if($this->userinfo){
            $cpa = $this->db->query("select * from tan_plat_ab_cpa where user_id = ".$this->userinfo['user_id']." and plat_en = '$plat_id' order by id desc limit 1")->row_array();
        }
        if($cpa){
            if(!$item['is_fast_login']){//非快速登录
                $interface = $this->plat_model->get_interface(array('plat_en'=>$item['name_en']));
                $item['login_url'] = $interface['login_link'];
            }else{
                $item['login_url'] = !$item['is_interest_mode'] ? site_url('mplat/login/'.$item['name_en']) : site_url('mplat/loginplat/'.$item['name_en']);
            }
        }
        
        //平台基本信息
        $baseinfo = $this->baseinfo($plat_id);
        //平台推荐
        $recommends = $this->plat_recommend($plat_id);
        //相关文章
        $articles = $this->plat_article($item['name_ch']);
        //相关问答
        $wendas = $this->plat_wenda($item['name_ch']);
        
        $this->assign('item', $item);
        $this->assign('cpa', $cpa);
        $this->assign('baseinfo', $baseinfo);
        $this->assign('recommends', $recommends);
        $this->assign('articles', $articles);
        $this->assign('wendas', $wendas);
        $this->assign('action', 'mplat');
        $this->display('mplat/detail.html');
    }
    //企业信息
    private function baseinfo($plat_id){
        //平台基本信息
        $baseinfo = $this->db->query("select qiyexinxi,pingtaifeiyong,tuanduijieshao,zhengjianziliao,bangonghuanjing,description,pingtaiduibitu from tan_plat_info where plat_en = '$plat_id' order by id limit 1")->row_array();
        $baseinfo['qiyexinxi'] = unserialize($baseinfo['qiyexinxi']);
        $baseinfo['pingtaifeiyong'] = unserialize($baseinfo['pingtaifeiyong']);
        $baseinfo['tuanduijieshao'] = unserialize($baseinfo['tuanduijieshao']);
        $baseinfo['zhengjianziliao'] = unserialize($baseinfo['zhengjianziliao']);
        $baseinfo['bangonghuanjing'] = unserialize($baseinfo['bangonghuanjing']);
        $baseinfo['qiyexinxi']['company_bg_type'] = $baseinfo['qiyexinxi']['company_bg_type'] ? $this->bgType[$baseinfo['qiyexinxi']['company_bg_type']]['title'] : $this->bgType[0]['title'];
        return $baseinfo;
    }
    //平台推荐
    private function plat_recommend($plat_en){
        $list = $this->db->query("select p.name_en,p.name_ch,p.logo_detail,p.add_interest,b.company_bg_type from tan_plat p left join tan_plat_baseinfo b on b.plat_en = p.name_en where p.name_en != '$plat_en' and p.is_recommend = 1 order by p.sort desc,p.id desc limit 6")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['add_interest'] = ($val['add_interest'] * 100)."%";
            $list[$key]['detail_url'] = site_url("mplat_".$val['name_en']);
            $class_str = $val['company_bg_type'] ? $this->bgType[$val['company_bg_type']]["class"] : $this->bgType[0]['class'];
            $list[$key]['class'] = $class_str;
        }
        return $list;
    }
    //相关文章
    private function plat_article($plat_ch){
        $where = "(a.title like '%$plat_ch%' or a.tags_name like '%$plat_ch%') and a.status = 1 order by a.hot desc,a.id desc";
        $list = $this->db->query("select a.id,a.authorid,a.title,a.summary,a.cat_id,a.thumb,a.tags_name,a.readnum,a.commentnum,a.likes,a.status,a.create_time,c.name cat_name,u.nickname from tan_bbs_article a left join tan_bbs_article_category c on c.id = a.cat_id left join tan_users_info u on u.user_id = a.authorid where ".$where." limit 6")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['detail_url'] = www_base_url("p/".encrypt_article_id($val['id']));
            $list[$key]['space_url'] = www_base_url("u/".encrypt_user_id($val['authorid']));
            $list[$key]['cat_url'] = www_base_url("p/cat-".$val['cat_id']);
            $list[$key]['create_time_str'] = date("Y-m-d",$val['create_time']);
            $list[$key]['title_str'] = mb_strcut($val['title'], 0, 55, "utf-8")."...";
            $tags = array();
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags[$v[1]] = array("tid"=>$v[1],"tname"=>$v[0],"turl"=>  www_base_url("p/tag-".$v[1])); 
                }
            }
            $list[$key]['tags'] = $tags;
        }
        return $list;
    }
    //相关问答
    private function plat_wenda($plat_ch){
        $where = "(w.title like '%$plat_ch%' or w.tags_name like '%$plat_ch%') and w.status = 1 and w.is_show = 1 order by w.hot desc,w.sort desc,w.id desc";
        $list = $this->db->query("select w.id,w.questioner_id,w.title,w.summary,w.tags_name,w.create_time,w.readnum,w.answernum,w.likes,w.focusnum,w.answer_id,w.answer_uid,u1.nickname questioner_nickname,u1.head_img questioner_headimg from tan_bbs_wenda w left join tan_users_info u1 on u1.user_id = w.questioner_id where $where limit 6")->result_array();
        foreach ($list as $key=>$val){
            $list[$key]['create_time'] = date("Y-m-d H:i",$val['create_time']);
            $list[$key]['detail_url'] = www_base_url("wenda/".encrypt_wenda_id($val['id']));
            $list[$key]['questioner_url'] = www_base_url("u/".encrypt_user_id($val['questioner_id']));
            $list[$key]['weixin_url'] = site_url("trcode")."?text=".urlencode(www_base_url("wenda/".encrypt_wenda_id($val['id'])))."&size=150&level=H";
            $answer = array();
            if($val['answernum']){//有回答
                if($val['answer_id']){//问答已被采纳
                    $answer = $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.id"=>$val['answer_id'],"a.user_id"=>$val['answer_uid']))->order_by("a.id desc")->get()->row_array();
                }else{//问题未被采纳
                    $answer =  $this->db->select("a.id,a.user_id,a.thumb,a.content,u.nickname,u.head_img")->from("bbs_wenda_answer a")->join("users_info u","u.user_id = a.user_id","left")->where(array("a.wenda_id"=>$val['id']))->order_by("a.likes desc,a.id desc")->get()->row_array();
                }
                if($answer){
                    $answer['space_url'] = www_base_url("u/".encrypt_user_id($answer['user_id']));
                    $answer['content'] = strip_tags(trim($answer['content']));
                }
                
            }
            $list[$key]['answer'] = $answer;
            $tags = array();
            if($val['tags_name']){
                $tags_arr = explode(",", $val['tags_name']);
                foreach ($tags_arr as $v){
                    $v = explode("_", $v);
                    $tags[$v[1]] = array("tid"=>$v[1],"tname"=>$v[0],"turl"=>  www_base_url("wenda/tag-".$v[1])); 
                }
            }
            $list[$key]['tags'] = $tags;
        }
        return $list;
    }
    //跳转页面
    function jump($plat){
        if(!$plat) redirect ("mplat");
        $item = $this->plat_model->get_plat(array('name_en'=>$plat,'is_show'=>1,"is_online"=>1,"is_work"=>1));
        if(!$item['is_show']) redirect (site_url('mplat_'.$plat));
        $where = array();
        $where['user_id'] = $this->userinfo['user_id'];
        $where['plat_en'] = $item['name_en'];
        $cpa = $this->plat_model->check_ab_cpa($where);
        if($cpa){
            $url = !$item['is_interest_mode'] ? site_url('mplat/login/'.$item['name_en']) : site_url('mplat/loginplat/'.$item['name_en']);
            redirect($url);
        }
        
        if($item['is_fast_reg'] == 0){
            $interface = $this->plat_model->get_interface(array('plat_en'=>$item['name_en']));
            $reg_link = $interface['reg_link'];
            $html =  "<script>window.onload=function(){window.location.href='".$reg_link."';}</script>";
            echo $html;die;
        }
        $item['logo_detail'] = strstr($item['logo_detail'], "http://") ? $item['logo_detail'] : $this->img_url.$item['logo_detail'];
        $this->assign('action', 'mplat');
        $this->assign('reg_url', $item['is_new_document'] ? site_url('mplat/regplat') : site_url('mplat/reg'));
        $this->assign('item', $item);
        $this->display('mplat/jump.html');
    }
    
    //一键登录
    function login($plat){
        
        !$plat ? redirect('mplat') : '';
        $plat = $this->plat_model->get_plat(array('name_en'=>$plat,'is_show'=>1));
        if(!$plat) redirect('mplat');
        $plat_type = $plat['plat_type'];
        $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
        $postData = array();//构造请求参数
        $where = array();
        $where['plat_en'] = $plat['name_en'];
        $where['user_id'] = $this->userinfo['user_id'];
        $cpa = $this->plat_model->check_ab_cpa($where);
        $accessKey = $plat['access_key'];//平台密钥
        $postData['from'] = 'tanliuliu';
        $postData['username'] = $this->user_info['username'];
        $postData['usernamep'] = $cpa['usernamep'];
        $postData['timestamp'] = time();
        $sign = strtolower(md5($accessKey.$postData['from'].$postData['timestamp'].$postData['username'].$postData['usernamep'].$accessKey));
        $postData['sign'] = $sign;
        //写入日志记录
        $log_data = array();
        $log_data['user_id'] = $this->user_info['user_id'];
        $log_data['events'] = 'fastlogin';
        $log_data['content'] = JSON($postData);
        $log_data['ip'] = $this->input->ip_address();
        $log_data['create_time'] = time();
        $this->users_log_model->insert($log_data);
        $login_interface_link = $interface['login_link'];//一键登录接口
        if(!$plat['is_fast_login']){
            header("Location:".$login_interface_link);exit;
        }
        $this->assign('from', 'tanliuliu');
        $this->assign('username',$postData['username']);
        $this->assign('usernamep', $postData['usernamep']);
        $this->assign('timestamp',  $postData['timestamp']);
        $this->assign('sign', $sign);
        $this->assign('login_interface_link', $login_interface_link);
        $this->display('mplat/login.html');
    }
    
    //一键注册
    function reg(){
        if($_POST){
            
            $SSID = isset($_POST['keyCode']) ? trim($_POST['keyCode']) : "";
            if($SSID != $this->session_id){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            if(!$this->userinfo){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            
            $mess = array();
            $plat = trim($_POST['plat']);
            $plat = $this->plat_model->get_plat(array('name_en'=>$plat,'is_show'=>1,"is_online"=>1,"is_work"=>1));
            if(!$plat){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = "您访问的平台不存在或已经下线";
                echo JSON($mess);exit;
            }
            //接口
            $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
            $accessKey = $plat['access_key'];
            $postData = array();//构造请求参数
            $postData['from'] =  $_POST['plat'] == 'hyjf' ? '40' :  'tanliuliu';
            $postData['username'] = $this->user_info['username'];
            $postData['mobile'] = $this->user_info['mobile'];
            $postData['email'] = $this->user_info['email'];
            $postData['timestamp'] = time();
            $sign = strtolower(md5($accessKey.$postData['email'].$postData['from'].$postData['mobile'].$postData['timestamp'].$postData['username'].$accessKey));
            $postData['sign'] = $sign;
            $reg_interface_link = $interface['reg_link'];//一键登录接口
            $result = $this->crypt->POST_Api($reg_interface_link,$postData);
            $result = json_decode($result,true);
            //写入日志记录
            $log_data = array();
            $log_data['user_id'] = $this->user_info['user_id'];
            $log_data['events'] = 'fastreg';
            $log_data['content'] = JSON($postData).'|'.JSON($result);
            $log_data['ip'] = $this->input->ip_address();
            $log_data['create_time'] = time();
            $this->users_log_model->insert($log_data);
            
            if($result['status'] != 1){
                $usernamep = $result['usernamep'];
                $regtime = $result['regtime'];
                
                $data = array();
                $data['user_id'] = $this->user_info['user_id'];
                $data['plat_id'] = $plat['id'];
                $data['plat_en'] = $plat['name_en'];
                $data['usernamep'] = $usernamep;
                $data['reg_time'] = $regtime;
                $this->plat_model->insert_ab_cpa($data);
                
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "快速注册成功";
                $mess["data"] = "<p>弹溜溜已帮您成功注册新账号：<span>".$result['usernamep']."</span></p>
                                 <a href='javascript:void '  data-url='".site_url('mplat/login/'.$plat['name_en'])."' style='width: 240px;height: 45px;line-height: 45px;font-size: 18px;color: #FFFFFF;background: #53baff;box-shadow: 0px 1px 0px 0px rgba(83,186,255,0.3);'>快速登录</a>";
                echo json_encode($mess,JSON_HEX_TAG);exit;
            }else{
                $mess['errorMsg'] = $result['errmsg'];
                $mess['errorCode'] = 1000;
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
        }else{
            $mess['reqStatus'] = false;
            $mess['errorCode'] = 1001;
            $mess['errorMsg'] = "非法访问";
            echo JSON($mess);exit; 
        }
    }
    
    //新一键登录（SSO）接口
    function loginplat($plat){
        !$plat ? redirect('mplat') : '';
        $plat = $this->plat_model->get_plat(array('name_en'=>$plat,'is_show'=>1));
        if(!$plat) redirect('mplat');
        $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
        $postData = array();//构造请求参数
        $where = array();
        $where['plat_en'] = $plat['name_en'];
        $where['user_id'] = $this->userinfo['user_id'];
        $cpa = $this->plat_model->check_ab_cpa($where);
        $accessKey = $plat['access_key'];//平台密钥
        $postData['from'] = 'tan66';
        $postData['usernamep'] = $cpa['usernamep'];
        $postData['timestamp'] = time();
        $sign = strtolower(md5($accessKey.$postData['from'].$postData['timestamp'].$postData['usernamep'].$accessKey));
        $postData['sign'] = $sign;
        //写入日志记录
        $log_data = array();
        $log_data['user_id'] = $this->user_info['user_id'];
        $log_data['events'] = 'fastlogin';
        $log_data['content'] = JSON($postData);
        $log_data['ip'] = $this->input->ip_address();
        $log_data['create_time'] = time();
        $this->users_log_model->insert($log_data);
        $login_interface_link = $interface['login_link'];//一键登录接口
        if(!$plat['is_fast_login']){
            header("Location:".$login_interface_link);exit;
        }
        $this->assign('from', 'tan66');
        $this->assign('usernamep', $postData['usernamep']);
        $this->assign('timestamp',  $postData['timestamp']);
        $this->assign('sign', $sign);
        $this->assign('login_interface_link', $login_interface_link);
        $this->display('mplat/loginplat.html');
    }
    
    //新一键注册接口
    function regplat(){
        if($_POST){
            
            $SSID = isset($_POST['keyCode']) ? trim($_POST['keyCode']) : "";
            if($SSID != $this->session_id){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            if(!$this->userinfo){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            
            $mess = array();
            $plat = trim($_POST['plat']);
            $plat = $this->plat_model->get_plat(array('name_en'=>$plat,'is_show'=>1));
            if(!$plat){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = "您访问的平台不存在或已经下线";
                echo JSON($mess);exit;
            }
            $plat_info = $this->db->query("select notice_msg from tan_plat_info where plat_en = '$plat[name_en]' order by id desc limit 1")->row_array();
            //接口
            $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
            $accessKey = $plat['access_key'];
            $postData = array();//构造请求参数
            $postData['from'] =  $_POST['plat'] == 'hyjf' ? '40' :  'tan66';
            $postData['username'] = $this->user_info['username'];
            $postData['mobile'] = $this->user_info['mobile'];
            $postData['timestamp'] = time();
            $sign = strtolower(md5($accessKey.$postData['from'].$postData['mobile'].$postData['timestamp'].$postData['username'].$accessKey));
            $postData['sign'] = $sign;
            $reg_interface_link = $interface['reg_link'];//一键注册接口
//            echo $reg_interface_link;die;
            $result = $this->crypt->POST_Api($reg_interface_link,$postData);
            $result = json_decode($result,true);
            //写入日志记录
            $log_data = array();
            $log_data['user_id'] = $this->user_info['user_id'];
            $log_data['events'] = 'fastreg';
            $log_data['content'] = JSON($postData).'|'.JSON($result);
            $log_data['ip'] = $this->input->ip_address();
            $log_data['create_time'] = time();
            $this->users_log_model->insert($log_data);
            
            if($result && $result['status'] != 1 && $result['status'] == 0){
                $usernamep = $result['usernamep'];
                $regtime = $result['regtime'];
                
                $data = array();
                $data['user_id'] = $this->user_info['user_id'];
                $data['plat_id'] = $plat['id'];
                $data['plat_en'] = $plat['name_en'];
                $data['usernamep'] = $usernamep;
                $data['reg_time'] = $regtime;
                $this->plat_model->insert_ab_cpa($data);
                
                $mess['reqStatus'] = true;
                $mess['errorMsg'] = "快速注册成功";
                $mess['noticeMsg'] = $plat_info['notice_msg'] ? $plat_info['notice_msg'] : "";
                $mess["data"] = "<p>弹溜溜已帮您成功注册新账号：<span>".$result['usernamep']."</span></p>
                                 <a href='javascript:void '  data-url='".site_url('mplat/loginplat/'.$plat['name_en'])."' style='width: 240px;height: 45px;line-height: 45px;font-size: 18px;color: #FFFFFF;background: #53baff;box-shadow: 0px 1px 0px 0px rgba(83,186,255,0.3);'>快速登录</a>";
                echo json_encode($mess,JSON_HEX_TAG);exit;
            }else{
                $mess['errorMsg'] = $result['errmsg'];
                $mess['errorCode'] = 1000;
                $mess['reqStatus'] = false;
                echo JSON($mess);exit;
            }
        }else{
            $mess['reqStatus'] = false;
            $mess['errorCode'] = 1001;
            $mess['errorMsg'] = "非法访问";
            echo JSON($mess);exit; 
        }
    }
    
    //查询信息
    function query($plat_en){
        if($_POST){
            $SSID = isset($_POST['keyCode']) ? trim($_POST['keyCode']) : "";
            if($SSID != $this->session_id){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            if(!$this->userinfo){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            
            $plat = $this->plat_model->get_plat(array('name_en'=>$plat_en,'is_show'=>1));
            
            if(!$plat){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1007;
                $mess['errorMsg'] = "您访问的平台不存在或已经下线";
                echo JSON($mess);exit;
            }
            
            $plat_id = $plat['id'];
            $user_id = $this->user_info['user_id'];
            $cpa = $this->plat_model->check_ab_cpa(array('user_id'=>$user_id,'plat_en'=>$plat['name_en']));
            if(!$cpa){
                $mess['reqStatus'] = true;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = "没有查到您最新的体验数据哦！";
                echo JSON($mess);exit;
            }
            //构造请求参数
            $postData = array();
            $postData['plat_id'] = $plat_id;
            $postData['user_id'] = $user_id;
            $reg_interface_link = $this->remote_url['query_url'];//一键查询接口
            $result = $this->crypt->POST_Api($reg_interface_link,$postData);//发送post查询请求
            $result = json_decode($result,true);
            
            $rules = $this->plat_model->get_rules(array('plat_id'=>$plat_id,'is_show'=>1));
            //成功获取
            if($result && $result['result'] != null && $result['result'] == 1 ){
                $award = $result['award'];
                $exper = $result['exper'];
                if($award){
                    $mess['reqStatus'] = true;
                    $mess['errorCode'] = 1001;
                    $mess['errorMsg'] = "恭喜您，获取".  number_format($award)."溜溜币";
                    $mess['url'] = site_url("user/exper_list");
                }else{
                    $mess['reqStatus'] = true;
                    $mess['errorCode'] = 1000;
                    $mess['errorMsg'] = "没有查到您最新的体验数据哦！";
                }
                isset($_POST['ajax']) ? $mess['str'] = $this->set_up_rule($rules, $plat_id) : "";
            }else{
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = $result['info'];
            }
            echo json_encode($mess,JSON_HEX_TAG);exit;
        }
    }
    
    /**
     * 重构体验规则
     * @param type $rules
     */
    private function set_up_rule($rules,$plat_id){
        $rule_str = '';
        foreach ($rules as $key=>$val){
            $where = array();
            $where['plat_id'] = $plat_id;
            $where['rule_step'] = $val['step'];
            $where['user_id'] = $this->userinfo['user_id'];
            $award = $this->plat_model->get_award_list($where);
            $rules[$key]['is_step'] = $award ? 1 : "";
            $rules[$key]['is_receive'] = $award['is_receive'] ? 1 : 0;
            $rules[$key]['award'] = number_format($val['award']);
            $rules[$key]['award_id'] = $award['id'];
        }
        $rule_str .= "<tr><th>体验要求</th><th>奖励溜溜币</th><th>奖励积分</th><th>奖励年化加息</th><th width='12%'>状态</th></tr>";
        foreach ($rules as $key=>$rule){
           
            $rule_str .= "<tr>";
            $rule_str .= "<td>".$rule['rule']."</td>";
            $rule_str .= "<td class='orange'>".$rule['award']."</td>";
            $rule_str .= "<td class='orange'>".$rule['exper']."</td>";
            $rule_str .= "<td class='orange'>".$rule['interest_desc']."</td>";
            $rule_str .= "<td>";
            if($rule['is_step']){
                if($rule['is_receive']){
                    $rule_str .= "已领取";
                }else{
                    $rule_str .= "<button class='receive-try-award' data-award-id='".$rule['award_id']."' data-url='".site_url('user/do_receive')."' data-key='".$this->session_id."'>领取奖励</button>";
                }
            }else{
                $rule_str .= "未体验";
            }
            $rule_str .= "</td>";
            $rule_str .= "</tr>";
        }
        return $rule_str;
    }
    
    /*********************壹佰金融start*************************************/
    function jump_pp100(){
        $plat_id = "pp100";
        $plat = $this->plat_model->get_info(array('name_en'=>$plat_id,'is_show'=>1));
        if(!$plat) redirect ("mplat");
        $user_id = $this->userinfo['user_id'];
        $where = array();
        $where['user_id'] = $this->userinfo['user_id'];
        $where['plat_en'] = $plat['name_en'];
        $cpa = $this->plat_model->check_ab_cpa($where);
        if($cpa){
            $url = site_url('mplat/login/'.$plat['name_en']);
            redirect($url);
        }
        $accessKey = $plat['access_key'];
        //接口
        $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
        $reg_link = $interface['reg_link'];
        $postData = array();
        $postData['pfCode'] = 'tanliuliu';
        $postData['channelId'] = "tll";
        $postData['tuid'] = $user_id;
        $sign = strtolower(md5($accessKey.$postData['pfCode'].$postData['tuid'].$accessKey));
        $postData['sign'] = $sign;
        
        $html = "<form id='plat_form_sub' action='".$reg_link."' method='post'>"
              . "<input type='hidden' name='pfCode' value='".$postData['pfCode']."'/>"  
              . "<input type='hidden' name='channelId' value='tll'/>"
              . "<input type='hidden' name='tuid' value='".$postData['tuid']."'/>"
              . "<input type='hidden' name='sign' value='".$sign."'/>"
              . "</form>"
              . "<script>window.onload=function(){document.getElementById('plat_form_sub').submit();}</script>";
        echo $html;die;
    }
    
    //查询壹佰金融
    function query_pp100(){
        $plat_en = "pp100";
        if($_POST){
            $SSID = isset($_POST['keyCode']) ? trim($_POST['keyCode']) : "";
            if($SSID != $this->session_id){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            if(!$this->userinfo){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1001;
                $mess['errorMsg'] = "访问超时，请重新登录";
                echo JSON($mess);exit;
            }
            
            $plat = $this->plat_model->get_plat(array('name_en'=>$plat_en,'is_show'=>1));
            
            if(!$plat){
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1007;
                $mess['errorMsg'] = "您访问的平台不存在或已经下线";
                echo JSON($mess);exit;
            }
            
            $plat_id = $plat['id'];
            $user_id = $this->user_info['user_id'];
            $cpa = $this->plat_model->check_ab_cpa(array('user_id'=>$user_id,'plat_en'=>$plat['name_en']));
            if(!$cpa){
                $mess['reqStatus'] = true;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = "没有查到您最新的体验数据哦！";
                echo JSON($mess);exit;
            }
            
            $accessKey = $plat['access_key'];
            $user_id = $this->user_info['user_id'];
            $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
            
            //构造请求参数
            $postData = array();
            $postData['pfCode'] = 'tanliuliu';
            $postData['platID'] = $plat['name_en'];
            $postData['userID'] = $this->user_info['user_id'];
            $postData['puserID'] = $cpa['usernamep'];
            $postData['channelId'] = 'tll';
            $postData['validType'] = 'sign';
            $postData['timestamp'] = time();
            $sign = strtolower(md5($accessKey.$postData['pfCode'].$postData['platID'].$postData['puserID'].$postData['timestamp'].$postData['userID'].$accessKey));
            $postData['sign'] = $sign;
            $reg_interface_link = $interface['query_link'];//一键查询接口
            $result = $this->crypt->GET_Api($reg_interface_link,$postData);//发送post查询请求
            $result = json_decode($result,true);
            //登录成功，写入日志记录
            $log_data = array();
            $log_data['user_id'] = $this->user_info['user_id'];
            $log_data['events'] = 'query';
            $log_data['content'] = JSON($postData).'|'.JSON($result);
            $log_data['ip'] = $this->input->ip_address();
            $log_data['create_time'] = time();
            $this->users_log_model->insert($log_data);
            
            $award_total = 0;
            $exper_total = 0;
            
            if($result && $result['status'] != 1 && $result['status'] == 0 ){//查询成功
                $rules = $this->plat_model->get_rules(array('plat_id'=>$plat_id,'is_show'=>1));
                //投资记录
                $list = $result['list'];
                if($list){//存在投资记录
                    $first_invest = $list[0];//取出第一条投资记录
                    if(!$cpa['is_data_bind']){//如果没有绑定
                        $amount = intval($first_invest['amount']);//投资金额
                        foreach ($rules as $rule){
                            $step_index = $rule['step'];
                            $min_amount = $rule['min_amount'];
                            $max_amount = $rule['max_amount'];
                            if($amount >= $min_amount && $amount <= $max_amount){//符合要求
                                $true_amount = $rule['true_amount'];//实际扣除金额
                                $award_amount = $rule['award'];//奖励金额
                                $exper_amount = $rule['exper'];//奖励经验
                                //增加奖励记录
                                $award_list = array();
                                $award_list['user_id'] = $this->user_info['user_id'];
                                $award_list['plat_id'] = $plat['id'];
                                $award_list['plat_en'] = $plat['name_en'];
                                $award_list['rule_step'] = $step_index;
                                $award_list['award'] = $award_amount;
                                $award_list['exper'] = $exper_amount;
                                $award_total += $award_amount;
                                $exper_total += $exper_amount;
                                $award_list['desc'] = '首次产品体验金额'.  sprintf('%0.2f',$amount).'元';
                                $award_list['create_time'] = time();
                                $invest_result = $this->plat_award_list_model->insert($award_list);
                                if($invest_result){//添加成功
                                    //更新绑定信息
                                    $cpa_data = array();
                                    $cpa_data['amount'] = $amount;
                                    $cpa_data['is_data_bind'] = 1;
                                    $cpa_data['is_finish'] = 1;
                                    $this->plat_model->update_ab_cpa($cpa_data,$cpa['id']);
                                    //更新平台信息
                                    $plat_data = array();
                                    $plat_data['pay_amount'] = $plat['pay_amount'] - $true_amount;
                                    if($plat_data['pay_amount'] <= 2000000){
                                        $plat_data['is_show'] = 0;
                                    }
                                    $this->plat_model->update_plat($plat_data,$plat['id']);
                                    //添加平台体验日志
                                    $plat_log = array();
                                    $plat_log['user_id'] = $this->user_info['user_id'];
                                    $plat_log['plat_id'] = $plat['id'];
                                    $plat_log['plat_en'] = $plat['name_en'];
                                    $plat_log['plat_balance'] = $plat_data['pay_amount'];
                                    $plat_log['award'] = $award_amount;
                                    $plat_log['true_award'] = $true_amount;
                                    $plat_log['experience'] = $exper_amount;
                                    $plat_log['create_time'] = time();
                                    $this->plat_model->insert_plat_log($plat_log);
                                }
                            }
                        }
                    }
                    $where = array();
                    $where['user_id'] = $user_id;
                    $where['plat_en'] = $plat['name_en'];
                    $where['order_nid'] = $first_invest['oid'];
                    $invest = $this->plat_model->get_plat_invest($where);
                    //投标订单不存在
                    if(!$invest){
                        $invest_data = array();
                        $invest_data['user_id'] = $user_id;
                        $invest_data['plat_id'] = $plat_id;
                        $invest_data['plat_en'] = $plat['name_en'];
                        $invest_data['order_nid'] = $first_invest['oid'];
                        $invest_data['borrow_nid'] = $first_invest['bid'];
                        $invest_data['title'] = $first_invest['title'];
                        $invest_data['url'] = $first_invest['url'];
                        $invest_data['amount'] = $first_invest['amount'];
                        $invest_data['invest_time'] = strtotime($first_invest['investtime']);
                        $invest_data['period'] = $first_invest['period'];
                        $invest_data['unit'] = $first_invest['unit'];
                        $invest_data['rate'] = $first_invest['rate'];
                        $invest_data['create_time'] = time();
                        $invest_id = $this->plat_model->insert_plat_invest_list($invest_data);
                    }
                }
                if($award_total){
                    $mess['reqStatus'] = true;
                    $mess['errorCode'] = 1001;
                    $mess['errorMsg'] = "恭喜您，获取".  number_format($award_total)."溜溜币";
                    $mess['url'] = site_url("user/exper_list");
                }else{
                    $mess['reqStatus'] = true;
                    $mess['errorCode'] = 1000;
                    $mess['errorMsg'] = "没有查到您最新的体验数据哦！";
                }
                isset($_POST['ajax']) ? $mess['str'] = $this->set_up_rule($rules, $plat_id) : "";
            }else{
                $mess['reqStatus'] = false;
                $mess['errorCode'] = 1000;
                $mess['errorMsg'] = $result['info'];
            }
            echo json_encode($mess,JSON_HEX_TAG);exit;
        }
    }
    
    
    //回绑接口
    function callback(){
        $mess = array();
        $plat_id = trim($_REQUEST['platID']);//商家平台唯一标识
        $user_id = trim($_REQUEST['userID']);//弹溜溜用户唯一标识
        $puser_id = trim($_REQUEST['puserID']);//商家用户唯一标识
        $sign = trim($_REQUEST['sign']);//校验码
        $plat = $this->plat_model->get_plat(array('name_en'=>$plat_id,'is_show'=>1));
        if(!$plat){
            $mess['status'] = "002";
            $mess['errmsg'] = "platID不存在或商家已下线";
            echo JSON($mess);exit;
        }
        if(!$user_id){
            $mess['status'] = "003";
            $mess['errmsg'] = "userID不能为空";
            echo JSON($mess);exit;
        }
        $uinfo = $this->users_model->get_user_by_uid($user_id);
        if(!$uinfo){
            $mess['status'] = "003";
            $mess['errmsg'] = "userID非法参数";
            echo JSON($mess);exit;
        }
        if(!$puser_id){
            $mess['status'] = "005";
            $mess['errmsg'] = "puserID不能为空";
            echo JSON($mess);exit;
        }
        $access_key = $plat['access_key'];
        $sign_c = strtolower(md5($access_key.$plat_id.$puser_id.$user_id.$access_key));
        //校验sign
        if($sign_c != $sign){
            $mess['status'] = "006";
            $mess['errmsg'] = "sign校验失败";
            echo JSON($mess);exit;
        }
        $where = array();
        $where['user_id'] = $user_id;
        $where['plat_en'] = $plat['name_en'];
        $where['usernamep'] = $puser_id;
        //检测用户是否绑定过了
        $cpa = $this->plat_model->check_ab_cpa($where);
        
        if($cpa){
            $mess['status'] = "004";
            $mess['errmsg'] = "userID不能重复绑定";
            echo JSON($mess);exit;
        }
        $cpa_data = array();
        $cpa_data['user_id'] = $uinfo['user_id'];
        $cpa_data['plat_id'] = $plat['id'];
        $cpa_data['plat_en'] = $plat['name_en'];
        $cpa_data['usernamep'] = $puser_id;
        $cpa_data['reg_time'] = time();
        //绑定数据
        $result = $this->plat_model->insert_ab_cpa($cpa_data);
        
        //写入日志记录
        $log_data = array();
        $log_data['user_id'] = $user_id;
        $log_data['events'] = 'callback';
        $log_data['content'] = JSON($_REQUEST);
        $log_data['ip'] = $this->input->ip_address();
        $log_data['create_time'] = time();
        $this->users_log_model->insert($log_data);
        
        if($result){
            $mess['status'] = "000";
            $mess['errmsg'] = "绑定成功";
        }else{
            $mess['status'] = "001";
            $mess['errmsg'] = "绑定失败";
        }
        
        echo JSON($mess);exit;
    }
    
    /*********************壹佰金融start*************************************/
    function jump_koudailc(){
        $plat_id = "koudailc";
        $plat = $this->plat_model->get_info(array('name_en'=>$plat_id,'is_show'=>1));
        if(!$plat) redirect ("mplat");
        $user_id = $this->userinfo['user_id'];
        $where = array();
        $where['user_id'] = $this->userinfo['user_id'];
        $where['plat_en'] = $plat['name_en'];
        $cpa = $this->plat_model->check_ab_cpa($where);
        if($cpa){
            $url = site_url('mplat/login/'.$plat['name_en']);
            redirect($url);
        }
        $accessKey = $plat['access_key'];
        //接口
        $interface = $this->plat_model->get_interface(array('plat_en'=>$plat['name_en']));
        $reg_link = $interface['reg_link'];
        $postData = array();
        $postData['from'] = 'tan66';
        $postData['platID'] = "koudailc";
        $postData['userID'] = $user_id;
        $postData['timestamp'] = time();
        $sign = strtolower(md5($accessKey.$postData['from'].$postData['platID'].$postData['timestamp'].$postData['userID'].$accessKey));
        $postData['sign'] = $sign;
        
        $html = "<form id='plat_form_sub' action='".$reg_link."' method='get'>"
              . "<input type='hidden' name='from' value='".$postData['from']."'/>"  
              . "<input type='hidden' name='platID' value='".$postData['platID']."'/>"  
              . "<input type='hidden' name='userID' value='".$postData['userID']."'/>"  
              . "<input type='hidden' name='timestamp' value='".$postData['timestamp']."'/>"  
              . "<input type='hidden' name='sign' value='".$sign."'/>"
              . "</form>"
              . "<script>window.onload=function(){document.getElementById('plat_form_sub').submit();}</script>";
        echo $html;die;
    }
    
}
